package com.bulkmail.sender;

import java.math.BigInteger;
import java.security.SecureRandom;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MimeApp {

	public void sendMime(String location, boolean hasAttach,
			DataSession dataSession) {
		ApplicationContext context = new ClassPathXmlApplicationContext(
				"/main/resources/file.xml");

		MimeMailMail mm = (MimeMailMail) context.getBean("mailMail");
		int i;
		String mailNb = "";
		String secure = "";

		for (i = 1; i <= dataSession.getNrEmails(); i++) {
			if (dataSession.getAddCounter()) {
				mailNb = "[" + i + "]";
			}
			if (dataSession.getAddRandomSubject()) {
				SecureRandom random = new SecureRandom();
				secure = new BigInteger(130, random).toString(32);
			}
			mm.sendMail(location, hasAttach, dataSession, mailNb, secure);

			try {
				Thread.sleep(dataSession.getSeconds());
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
